package com.IR.fenxiao.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.IR.shop.mapper.DistributionMapper;
import com.IR.shop.po.Distribution;
import com.IR.shop.po.DistributionExample;
import com.IR.shop.po.Users;

@Service
public class BDistributionBiz {
	@Resource
	private DistributionMapper dismapper;
	
	private List<Distribution> listdis;
	private List<Users> listuser;
	public List<Distribution> getListdis() {
		return listdis;
	}
	public void setListdis(List<Distribution> listdis) {
		this.listdis = listdis;
	}
	public List<Users> getListuser() {
		return listuser;
	}
	public void setListuser(List<Users> listuser) {
		this.listuser = listuser;
	}
	//查询全部用户
	public List<Distribution> findDisAll(){
		DistributionExample  de = new DistributionExample();
		listdis=dismapper.selectByExample(de);
		//System.out.println(listdis.size());
		return listdis;
	}
	//查询一级分丝用户
	public List<Distribution> findDisOneDown(Long did){
		DistributionExample example=new DistributionExample();
		DistributionExample.Criteria c=example.createCriteria();
		//Long did = 20180906205001225l;
		//did属性是否等于did
		c.andDidEqualTo(did);
		return dismapper.selectByExample(example);
		//System.out.println(listdis.size());
	}
	//查询二级分丝用户
	public List<Distribution> findDisTwoDown(Long did){
		List<Distribution> listdis3 =new ArrayList<Distribution>();
		//查询第一级
		DistributionExample example1=new DistributionExample();
		DistributionExample.Criteria c=example1.createCriteria();
		//Long did = 20180906205001225l;
		c.andDidEqualTo(did);
		List<Distribution> listdis1=dismapper.selectByExample(example1);
		for(Distribution list1:listdis1) {
			//创建第二次查询
			DistributionExample example2=new DistributionExample();
			DistributionExample.Criteria c1=example2.createCriteria();
			c1.andDidEqualTo(list1.getDxid());
			//第二次查询集合listdis1
			List<Distribution> listdis2=dismapper.selectByExample(example2);
			if(listdis2!=null) {
				for(Distribution list2:listdis2) {
					//System.err.println(list2.getDxid());
					listdis3.add(list2);
				}
			}
		}
		listdis=listdis3;
		return listdis;
	}
	
	//查询一级老板
	public Distribution findDisOneUp(Long did){
		DistributionExample example1=new DistributionExample();
		DistributionExample.Criteria c=example1.createCriteria();
		Long dxid =20180907111709954l;
		c.andDxidEqualTo(dxid);
		List<Distribution> listdis1=dismapper.selectByExample(example1);
		System.err.println(listdis1.get(0).getDid());
		return listdis1.get(0);
	}
	
	//查询二级老板
	public Distribution findDisTwoUp(Long did){
		//查询一级老板
		DistributionExample example1=new DistributionExample();
		DistributionExample.Criteria c=example1.createCriteria();
		Long dxid =20180907111709954l;
		c.andDxidEqualTo(dxid);
		List<Distribution> listdis1=dismapper.selectByExample(example1);
		//查询二级老板
		DistributionExample example2=new DistributionExample();
		DistributionExample.Criteria c2=example2.createCriteria();
		Long dxid2 =listdis1.get(0).getDid();
		c2.andDxidEqualTo(dxid2);
		List<Distribution> listdis2=dismapper.selectByExample(example2);
		//System.err.println(listdis1.get(0).getDid());
		System.err.println(listdis2.get(0).getDid());
		return listdis2.get(0);
	}
		
}
